<?php

namespace App\Plugin\HostServer\Admin;


use App\Plugin\HostServer\Models\PnHostSvDomain;

use Illuminate\Http\Request;


class DomainController extends BaseController
{
    public $pageName='域名';
    public function setModel()
    {
        return $this->model=new PnHostSvDomain();
    }
    public function indexData()
    {


        $item = [];
        $item['all_create_url'] = action($this->route['controller_name'] . '@allCreate', \request()->all());
        $item['all_post_url'] = action($this->route['controller_name'] . '@allCreatePost');

        return $item;
    }
    public function checkRule($id = '')
    {

        return [
            'name' =>[
                "required"
            ],
            'origin_money' =>[
                "required"
            ],
            'register_money' =>[
                "required"
            ],
            'renewal_money' =>[
                "required"
            ]

        ];
    }
    public function checkRuleMsg()
    {
        return [
            'name' =>'域名后缀',
            'origin_money' =>'市场价',
            'register_money' =>'首年注册价',
            'renewal_money' =>'续费价格'

        ];
    }




    /**
     * 批量添加设置数据
     * @param Request $request
     * @return array|void
     */
    public function allCreateSetData(Request $request){
        $name_arr=explode("\n",$request->input('name'));
        $origin_money=explode("\n",$request->input('origin_money'));
        $register_money=explode("\n",$request->input('register_money'));
        $renewal_money=explode("\n",$request->input('renewal_money'));
        $all=$request->all();
        $arr=[];
        if(empty($name_arr))
        {
            return [];
        }

        foreach ($name_arr as $k=>$v)
        {

            unset($all['_token']);
            $all['name']=$v;
            $all['origin_money']=$origin_money[$k]??'';
            $all['register_money']=$register_money[$k]??'';
            $all['renewal_money']=$renewal_money[$k]??'';

            $arr[]=$all;
        }
        return $arr;
    }
    public function orderBy($model, $order_by_name, $order_by_type)
    {
        return $model->orderBy('id', 'asc')->orderBy('sort', 'desc');
    }

    public  function allAfterEvent()
    {
        PnHostSvDomain::updateCache();
    }

}
